package com.aigou.admin.service.impl;

import com.aigou.admin.dao.SearchHistoryDao;
import com.aigou.admin.dao.impl.SearchHistoryDaoIpml;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.Sales;
import com.aigou.admin.entity.SearchHistory;
import com.aigou.admin.service.SearchHistoryService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chai
 * @date 2024/12/8 0008
 * @Description
 */
@Service
@AllArgsConstructor
public class SearchHistoryServiceImpl implements SearchHistoryService {

    private  final SearchHistoryDao searchHistoryDao;

    @Override
    public List<SearchHistory> findAll() {
        return  searchHistoryDao.selectAll();
    }




    @Override
    public SearchHistory findById(String id) {
        return  searchHistoryDao.selectById(id) ;
    }

    @Override
    public Boolean save(SearchHistory searchHistory) {
        return searchHistoryDao.insert(searchHistory);
    }

    @Override
    public Boolean update(SearchHistory searchHistory) {
        return searchHistoryDao.update(searchHistory);
    }

    @Override
    public Boolean remove(String id) {
        return searchHistoryDao.delete(id);
    }

    @Override
    public PageEntity<SearchHistory> findSearchHistoryPage(Integer current, Integer pageSize) {
        int total = searchHistoryDao.selectOrderCount();
        //分页查询用户数据 limit
        List<SearchHistory> searchHistories = searchHistoryDao.selectSearchHistoryByLimit((current-1) * pageSize,pageSize);
        //发送数据给前端
        PageEntity<SearchHistory> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(searchHistories);
        return pageEntity;
    }

    @Override
    public PageEntity<SearchHistory> findSearchHistoryLikePage(Integer current, Integer pageSize, String k) {
        int total = searchHistoryDao.selectOrderCountByLike(k);
        //分页查询用户数据 limit
        List<SearchHistory> searchHistories = searchHistoryDao.selectSearchHistoryByLike((current-1) * pageSize,pageSize,k);
        //发送数据给前端
        PageEntity<SearchHistory> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(searchHistories);
        return pageEntity;
    }


}
